﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace DllRegister
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string regasmPath = RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";

            // Get the location of our DLL.
            string componentPath = "L:\\Telas CallBack\\LinxDtef\\bin\\x86\\Debug\\LinxDtef.dll";

            // Execute regasm.
            Process p = new Process();
            p.StartInfo.FileName = regasmPath;
            p.StartInfo.Arguments = "\"" + componentPath + "\" /tlb /codebase";
            p.StartInfo.Verb = "runas";          // To run as administrator.
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            p.Start();
            p.WaitForExit();
            MessageBox.Show("Dll Registrada com sucesso !");
        }

        private void button2_Click(object sender, EventArgs e)
        {

            // Get the location of regasm.
            string regasmPath = RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";

            // Get the location of our DLL.
            //string componentPath = typeof(clsRegisterDll).Assembly.Location;
            string componentPath = "L:\\Telas CallBack\\LinxDtef\\bin\\x86\\Debug\\LinxDtef.dll";


            // Execute regasm.
            Process p = new Process();

            p.StartInfo.FileName = regasmPath;
            p.StartInfo.Arguments = "/u \"" + componentPath + "\" /tlb /codebase";
            p.StartInfo.Verb = "runas";          // To run as administrator.
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            p.Start();
            p.WaitForExit();

            // Delete the TLB file.
            File.Delete(Path.Combine(Path.GetDirectoryName(componentPath), Path.GetFileNameWithoutExtension(componentPath) + ".tlb"));
            MessageBox.Show("Dll Desregistrada com sucesso !");
        }
    }
}
